﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

namespace ABLocal
{
    public class UnityForAndroid : MonoBehaviour
    {
        public Text callbackText;
        public Button LoginBtn;
        public RawImage sp;

        // Start is called before the first frame update
        void Start()
        {
            LoginBtn.onClick.AddListener(LoginClick);
        }
        AndroidJavaObject jo;
        public void LoginClick()
        {
            AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            jo = jc.GetStatic<AndroidJavaObject>("currentActivity");

            jo.Call("LoginQQ");
        }
        public void AndroidCallBack(string callbackinfo)
        {
            callbackText.text = callbackinfo;
        }
        public void SetHead(string callbackinfo)
        {
            Debug.Log($"----------------->>>{callbackinfo}");
            callbackText.text = callbackinfo;
            StartCoroutine("LoadHead", callbackinfo);
        }

        IEnumerator LoadHead(string url)
        {
            using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url.Replace("\\", "")))
            {
                yield return uwr.SendWebRequest();
                if (uwr.isNetworkError || uwr.isHttpError)
                {
                    Debug.Log(uwr.error);
                }
                else
                {
                    // Get downloaded asset bundle
                    var texture = DownloadHandlerTexture.GetContent(uwr);
                    sp.texture = texture;
                }
            }
        }
    }
}